<template>
	<view>
		<u-tabs :list="tabBars" line-width="120" :scrollable="false" :current="tabIndex" @change="tapTab"></u-tabs>
		<view class="content">
			<swiper :current="tabIndex" class="swiper-box" :duration="300" @change="changeTab">
				<swiper-item>
					<inspect ref="inspect"></inspect>
				</swiper-item>
		
				<swiper-item>
					<defect ref="defect"></defect>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import inspect from './components/index-content.vue'
	import defect from 'pages/business/defect/offline/components/index-content.vue'
	
	export default {
		components: {
			inspect,
			defect
		},
		data() {
			return {
				tabIndex: 0,
				tabBars: [
					{ name: this.$t('inspection.offline.offlineTask') },
					{ name: this.$t('inspection.offline.offlineDefect') }
				]
			}
		},
		methods: {
			changeTab(e) {
				this.tabIndex = e.target.current
				if(this.tabIndex === 0) {
					this.$refs.inspect.atTop()
				} else if(this.tabIndex === 1) {
					this.$refs.defect.atTop()
				}
			},
			tapTab(e) {
				this.tabIndex = e.index
			},
			reload(index) {
				if(index === 0) {
					this.$refs.inspect.atTop()
				} else if(index === 1) {
					this.$refs.defect.atTop()
				}
			}
		},
		onBackPress() {
			uni.reLaunch({
				url: '/pages/platform/login/index'
			});
			return true;
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #F1F1F1;
	}
	
	.swiper-box {
		/* #ifdef H5 */
		height: calc(100vh - 88px);
		/* #endif */
		/* #ifdef APP-PLUS */
		height: calc(100vh - 44px);
		/* #endif */
	}
</style>
